package com.select.course.controller;


import com.select.course.service.CourseRoomService;
import com.select.course.utils.PageUtils;
import com.select.course.utils.R;
import com.select.course.vo.CourseRoomVo;
import com.select.course.vo.PageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/courseroom")
@CrossOrigin
@RestController
public class CourseRoomController {

    @Resource
    private CourseRoomService courseRoomService;

    @PostMapping("/getallcr")
    public R getAllCourse(@RequestBody PageVo pageVo) {
        PageUtils pageUtils = courseRoomService.getAllCourse(pageVo);
        return R.ok().put("data", pageUtils);
    }

    @PutMapping("/updateclassroom")
    public R getAllCourse(@RequestBody CourseRoomVo courseRoomVo) {
        R r = courseRoomService.updateCourseRoom(courseRoomVo);
        return r;
    }

    @GetMapping("/getClassRoom")
    public R getAllCourse() {
        List<String> courseRoom = courseRoomService.getClassRoom();
        return R.ok().put("data", courseRoom);
    }

    @GetMapping("/classroomcheck/{classroomid}")
    public R classRoomCheck(@PathVariable Long classroomid) {
        R r = courseRoomService.classRoomCheck(classroomid);
        return r;
    }

    @GetMapping("/classroomcheckbyclassname/{name}")
    public R classRoomCheckByClassName(@PathVariable String name) {
        R r = courseRoomService.classRoomCheckByName(name);
        return r;
    }

    @PostMapping("/addclassroom")
    public R addClassRoom(@RequestBody CourseRoomVo courseRoomVo) {
        R r = courseRoomService.addClassRoom(courseRoomVo);
        return r;
    }

    @DeleteMapping("/deleteclassroom/{id}")
    public R deleteClassRoom(@PathVariable Long id) {
        boolean b = courseRoomService.removeById(id);
        if (b) {
            return R.ok();
        }
        return R.error(111, "删除失败！");
    }
}
